/**
 * @author jprieur
 */

package mygui;

import java.awt.event.*;
import javax.swing.*;
import kernel.*;

public class ActionNew extends AbstractAction
{

    MonIHM _gui;
    
    public ActionNew (MonIHM gui){
	_gui = gui;
	
	putValue(AbstractAction.NAME,"New");
	putValue(AbstractAction.SHORT_DESCRIPTION,"Create a new simulation");
	putValue(AbstractAction.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_N,KeyEvent.CTRL_MASK ));
	putValue(AbstractAction.SMALL_ICON,UIM.createImageIcon("images/new.png","Add Mobile Station"));
	
    }

    public void actionPerformed(ActionEvent e)
    {
	Simulator kernel_old = _gui.getSimulator();
	Simulator kernel;

	String outputdir = kernel_old.getResultManager().getResultDir();
	String oldname = kernel_old.getName();


	int old_mode = _gui._kernel.getMode();
	if(old_mode == Simulator.SENSOR){
	    kernel = new SensorSimulator(_gui, old_mode);
	}else{
	    kernel = new Simulator(_gui, old_mode);
	}
	
	kernel.getResultManager().setResultDir(outputdir);
	kernel.setName(oldname);
	
	//_gui.getSimulator().stopSim();
	_gui.setSimulator(kernel);
	_gui._display.setMode(DisplayPanel.Mode.ARROW);



	//sim.restoreTimerForSnap();

	//sim.UpdateIHM(_gui);					// canvas
	//_gui._display.launched = false;
	//_gui.informationPane.updateInfos();
	
	// Test : get information about the simulator
	//	  System.out.println(sim.xmlDump());
    } 
}
